package com.bilgeadam.hibernate.model.bll;

import java.util.List;

import com.bilgeadam.hibernate.model.dal.GenericDal;
import com.bilgeadam.hibernate.model.entity.GenericEntity;

/**
 * 
 * @author Bora SAYINER
 * @since Nov 21, 2014 4:04:47 PM
 * @version 1.0.0
 */
public abstract class AbstractBll<T, E extends GenericEntity<T>> implements GenericBll<T, E> {

	private final GenericDal<T, E> dal;

	public AbstractBll(GenericDal<T, E> dal) {
		this.dal = dal;
	}

	public List<E> getAll() {
		return dal.getAll();
	}

	public E findById(T id) {
		return dal.findById(id);
	}

	public boolean add(E entity) {
		boolean result = false;
		if (validateEntity(entity)) {
			result = dal.add(entity);
		}
		return result;
	}

	public boolean delete(E entity) {
		return dal.delete(entity);
	}

	public boolean update(E entity) {
		boolean result = false;
		if (validateEntity(entity)) {
			result = dal.update(entity);
		}
		return result;
	}

}
